---
title: "The Prodigal Child Returns? Attitudes Towards Return Migration in a Developing Economy"
author: "Melle Scholten"
date: "Last Updated 30 March 2025, after conditional acceptance"
output:
  html_document: default
  pdf_document: default
---

This is the replication data and code for the experimental component of the paper "The Prodigal Child Returns? Attitudes Towards Return Migration in Developing Economies." Replication data and code for the observational component of the paper are provided separately. 

Written in R version 4.4.1 (2024-06-14 ucrt) -- "Race for Your Life"

Runtime, approximately 30 seconds.

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

The following packages are necessary to replicate this code: `tidyverse`, `cjoint`, `vtable`, and `sensemakr`. If one or more of these packages are not installed on your machine, please install them:

```{r installpack}
# install.packages("tidyverse")
# install.packages("cjoint")
# install.packages("vtable")
# install.packages("sensemakr")
```

Load Libraries:
```{r libraries, message=FALSE}
library(tidyverse)
library(cjoint)
library(vtable)
library(sensemakr)
```

Import data:
```{r import}
conjoint_fc <- read.qualtrics("conjoint.csv", new.format = TRUE, letter = "P",
                               responses = c("conjoint1", "conjoint2", "conjoint3",
                                             "conjoint4", "conjoint5", "conjoint6"),
                               covariates = c("urbrur", "pol1", "pol2", "labor", "live1",
                                              "live2", "dem", "baseline"))

conjoint_rank <- read.qualtrics("conjoint.csv", new.format = TRUE, letter = "P",
                               ranks = c("slide11", "slide12", "slide21", "slide22", 
                                         "slide31", "slide32", "slide41", "slide42", 
                                         "slide51", "slide52", "slide61", "slide62"),
                               covariates = c("urbrur", "pol1", "pol2", "labor", "live1",
                                              "live2", "dem", "baseline"))
```

Clean data (FC):
```{r clean}
conjoint_clean <- conjoint_fc %>% 
  mutate(
    democracy = case_when(
      dem == 1 ~ 1,
      dem == 2 ~ 0,
      dem == 3 ~ 0,
      dem == 4 ~ NA
    ),
    demalt1 = case_when(
      dem == 1 ~ 1,
      dem == 2 ~ 0,
      dem == 3 ~ NA,
      dem == 4 ~ NA
    ), 
    demalt2 = case_when(
      dem == 1 ~ 1,
      dem == 2 ~ NA,
      dem == 3 ~ 0,
      dem == 4 ~ NA
    ), 
    right = case_when(
      pol1 == 1 ~ 1,
      pol2 == 1 ~ 1,
      pol1 == 4 ~ NA,
      TRUE ~ 0
    ),
    work = case_when(
      labor == 1 ~ 1,
      labor == 2 ~ 1,
      labor == 4 ~ 1,
      labor == 7 ~ NA,
      TRUE ~ 0
    ),
    work_alt = case_when(
      labor == 1 ~ 1,
      labor == 2 ~ 1,
      labor == 3 ~ 0,
      labor == 4 ~ 1,
      labor == 5 ~ NA,
      labor == 6 ~ NA,
      labor == 7 ~ NA
    ),
    urban = case_when(
      urbrur == 1 ~ 1,
      urbrur == 2 ~ 0,
      urbrur == 3 ~ NA
    ),
    former_mig = case_when(
      live1 == 1 ~ 1,
      live1 == 2 ~ 0,
      live1 == 3 ~ NA
    ),
    family = case_when(
      live2 == 1 ~ 1,
      live2 == 2 ~ 0,
      live2 == 3 ~ NA
    )) %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(selected)))) %>% 
  ungroup()

by_dem <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(democracy)))) %>% 
  ungroup()

by_alt1 <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(demalt1)))) %>% 
  ungroup()

by_alt2 <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(demalt2)))) %>% 
  ungroup()

by_work <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(work)))) %>% 
  ungroup()

by_work_alt <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(work_alt)))) %>% 
  ungroup()

by_right <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(right)))) %>% 
  ungroup()

by_urban <- conjoint_clean %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(urban)))) %>% 
  ungroup()
```

Clean data (rank):
```{r clean_rank}
conjoint_clean_rank <- conjoint_rank %>% 
  mutate(
    democracy = case_when(
      dem == 1 ~ 1,
      dem == 2 ~ 0,
      dem == 3 ~ 0,
      dem == 4 ~ NA
    ),
    right = case_when(
      pol1 == 1 ~ 1,
      pol2 == 1 ~ 1,
      pol1 == 4 ~ NA,
      TRUE ~ 0
    ),
    work = case_when(
      labor == 1 ~ 1,
      labor == 2 ~ 1,
      labor == 4 ~ 1,
      labor == 7 ~ NA,
      TRUE ~ 0
    ),
    work_alt = case_when(
      labor == 1 ~ 1,
      labor == 2 ~ 1,
      labor == 3 ~ 0,
      labor == 4 ~ 1,
      labor == 5 ~ NA,
      labor == 6 ~ NA,
      labor == 7 ~ NA
    ),
    urban = case_when(
      urbrur == 1 ~ 1,
      urbrur == 2 ~ 0,
      urbrur == 3 ~ NA
    ),
    former_mig = case_when(
      live1 == 1 ~ 1,
      live1 == 2 ~ 0,
      live1 == 3 ~ NA
    ),
    family = case_when(
      live2 == 1 ~ 1,
      live2 == 2 ~ 0,
      live2 == 3 ~ NA
    ),
    democracy = factor(democracy),
    right = factor(right),
    work = factor(work),
    urban = factor(urban),
    former_mig = factor(former_mig),
    family = factor(family)
  ) %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(selected)))) %>% 
  ungroup()

by_dem_rank <- conjoint_clean_rank %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(democracy)))) %>% 
  ungroup()

by_work_rank <- conjoint_clean_rank %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(work)))) %>% 
  ungroup()

by_right_rank <- conjoint_clean_rank %>% 
  group_by(respondentIndex) %>% 
  filter(!(any(is.na(right)))) %>% 
  ungroup()
```

Descriptive statistics (Table 7 in the appendix)
```{r descrstats}
ind_level <- read.csv("conjoint.csv") %>% 
  filter(!row_number() %in% c(1:2)) %>% 
  mutate(
    democracy = case_when(
      dem == 1 ~ 1,
      dem == 2 ~ 0,
      dem == 3 ~ 0,
      dem == 4 ~ NA
    ),
    right = case_when(
      pol1 == 1 ~ 1,
      pol2 == 1 ~ 1,
      pol1 == 4 ~ NA,
      TRUE ~ 0
    ),
    work = case_when(
      labor == 1 ~ 1,
      labor == 2 ~ 1,
      labor == 4 ~ 1,
      labor == 7 ~ NA,
      TRUE ~ 0
    ),
    urban = case_when(
      urbrur == 1 ~ 1,
      urbrur == 2 ~ 0,
      urbrur == 3 ~ NA
    ),
    former_mig = case_when(
      live1 == 1 ~ 1,
      live1 == 2 ~ 0,
      live1 == 3 ~ NA
    ),
    family = case_when(
      live2 == 1 ~ 1,
      live2 == 2 ~ 0,
      live2 == 3 ~ NA
    ),
    pref = case_when(
      baseline == 1 ~ 1,
      baseline == 2 ~ 0,
      baseline == 3 ~ NA
    )
  )
# Scroll down to the bottom rows for the summary statistics reported in the appendix. 
st(ind_level)
```

Unconditional AMCE (Figure 1)
```{r amce1}
# Using cjoint
amce1 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno + Política,
                      data = conjoint_clean, cluster = TRUE, respondent.id = "respondentIndex")

summary(amce1)

amce1_df <- tibble(
  attribute = c("Savings:", "(Baseline = No savings)", "Savings from abroad", 
                "Intended employment:", "(Baseline = Self-employed)", "Looking for work",
                "Country:", "(Baseline = United States)", "Venezuela",
                "Politics:", "(Baseline = No political ambition)", "Political ambition"),
  effect = c(NA, 0, 0.1665288, NA, 0, -0.1197178, NA, 0, -0.1864441, NA, 0, -0.1187526),
  lower_ci = c(NA, NA, 0.148984, NA, NA, -0.1354464, NA, NA, -0.2039192, NA, NA, -0.1351952),
  upper_ci = c(NA, NA, 0.1840736, NA, NA, -0.1039892, NA, NA, -0.168969, NA, NA, -0.10231)
)

amce1_plot <- ggplot(amce1_df, aes(x = factor(attribute, level=c("Political ambition",
                                                                 "(Baseline = No political ambition)",
                                                                 "Politics:",
                                                                 "Venezuela",
                                                                 "(Baseline = United States)",
                                                                 "Country:",
                                                                 "Looking for work", 
                                                                 "(Baseline = Self-employed)", 
                                                                 "Intended employment:",
                                                                 "Savings from abroad",
                                                                 "(Baseline = No savings)",
                                                                 "Savings:")), 
                                   y = effect)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.4, 0.75),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("fig1.eps", plot=amce1_plot, width=6.5, height=3.5, units="in")
```

AMCE conditional on employment (Figure 2)
```{r cond_work}
# Using cjoint
amce2 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto*work + País.de.retorno + Política,
              data = by_work, cluster = TRUE, respondent.id = "respondentIndex",
              respondent.varying = "work")

summary(amce2)

# amce2alt is the model reported in the main body of the paper, as it uses a more sensible coding for 
# entrepreneurial competition, i.e. excluding those not working at all such as the retired. 
amce2alt <- cjoint::amce(selected ~ Ahorros + Empleo.previsto*work_alt + País.de.retorno + Política,
                 data = by_work_alt, cluster = TRUE, respondent.id = "respondentIndex",
                 respondent.varying = "work_alt")

summary(amce2alt)

amce2_df <- tibble(
  Subgroup = rep(c("Entrepreneurial competitors", "Labor market competitors"), each = 3),
  attribute = rep(c("Intended employment:", "(Baseline = Self-employed)", "Looking for work"), 2),
  effect = c(NA,0,-0.14651, NA,0, -0.10586),
  lower_ci = c(NA,NA, -0.177574, NA,NA, -0.1266458),
  upper_ci = c(NA,NA, -0.115446, NA,NA, -0.0850742)
)
amce2_plot <- ggplot(amce2_df, aes(x = factor(attribute, level=c("Looking for work", 
                                                                 "(Baseline = Self-employed)", 
                                                                 "Intended employment:")), 
                                   y = effect, color = Subgroup)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.4, 0.75),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("fig2.eps", plot=amce2_plot, width=6.5, height=3.5, units="in")
```

ACIE conditional on democratic attitudes (Figure 3)
```{r cond_dem}
# Using cjoint
amce3 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno*Política*democracy,
              data = by_dem, cluster = TRUE, respondent.id = "respondentIndex",
              respondent.varying = "democracy")
summary(amce3)

amce3_df <- tibble(
  Subgroup = rep(c("Not pro-democracy", "Pro-democracy"), each = 9),
  attribute = rep(c("Country:", "(Baseline = United States)", "Venezuela",
                    "Politics:", "(Baseline = No political ambition)", "Political ambition",
                    "Country*Politics:", "(Baseline = USA*No ambition)", "Venezuela*Ambition"), 2),
  effect = c(NA,0,-0.1520335, NA,0, -0.1102295, NA,0, -0.2978579, # Not pro
             NA,0, -0.2126745, NA,0, -0.1256487, NA,0, -0.3308074), # Pro democracy
  lower_ci = c(NA,NA, -0.1857518, NA,NA, -0.1422539, NA,NA, -0.3682696,  
               NA,NA, -0.2348137, NA,NA, -0.1466746, NA,NA, -0.3783189),
  upper_ci = c(NA,NA, -0.1183152, NA,NA, -0.0782051, NA,NA, -0.2274463, 
               NA,NA, -0.1905353, NA,NA, -0.1046228, NA,NA, -0.2832959)
)
amce3_plot <- ggplot(amce3_df, aes(x = factor(attribute, level=c("Venezuela*Ambition", 
                                                                 "(Baseline = USA*No ambition)", 
                                                                 "Country*Politics:",
                                                                 "Political ambition",
                                                                 "(Baseline = No political ambition)",
                                                                 "Politics:",
                                                                 "Venezuela",
                                                                 "(Baseline = United States)",
                                                                 "Country:")), 
                                   y = effect, color = Subgroup)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.3, 0.5),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("fig3.eps", plot=amce3_plot, width=6.5, height=3.5, units="in")
```

AMCEs in table format (Tables 3, 4, and 5 in the appendix)
```{r table}
summary(amce1)
summary(amce2alt)
print(amce2alt$cond.estimates)
summary(amce3)
print(amce3$cond.estimates)
```

Sensitivity analysis (Figure A6 in the appendix)
```{r sense}
model <- lm(selected ~ Ahorros + Empleo.previsto + País.de.retorno + Política,
            data = conjoint_clean)

sense <- sensemakr(model = model, 
                   treatment = "AhorrosTiene ahorros ganados en el extranjero",
                   benchmark_covariates = "País.de.retornoVenezuela",
                   kd = 1:3)
ovb_minimal_reporting(sense, format = "pure_html")
sensplot <- plot(sense, sensitivity.of = "t-value")
setEPS()
postscript("figa6.eps")
plot(sense, sensitivity.of = "t-value")
dev.off()
```

Robustness extensions: democracy or left-right attitudes? (Figure A7 and Table 6 in the appendix)
```{r leftright}
# Using cjoint
amce5 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno*Política*right,
              data = by_right, cluster = TRUE, respondent.id = "respondentIndex",
              respondent.varying = "right")
summary(amce5)

amce5_df <- tibble(
  Subgroup = rep(c("Left-wing", "Right-wing"), each = 9),
  attribute = rep(c("Country:", "(Baseline = United States)", "Venezuela",
                    "Politics:", "(Baseline = No political ambition)", "Political ambition",
                    "Country*Politics:", "(Baseline = USA*No ambition)", "Venezuela*Ambition"), 2),
  effect = c(NA,0,-0.15960823, NA,0, -0.09365373, NA,0, -0.2357726, # Left
             NA,0, -0.221811, NA,0, -0.119129	, NA,0, -0.3530416), # Right
  lower_ci = c(NA,NA, -0.1936276, NA,NA, -0.1262787, NA,NA, -0.3063936,
               NA,NA, -0.2486726, NA,NA, -0.1443356, NA,NA, -0.4117198),
  upper_ci = c(NA,NA, -0.1255889, NA,NA, -0.06102871, NA,NA, -0.1651516,
               NA,NA, -0.1949494, NA,NA, -0.09392244, NA,NA,  -0.2943634)
)
amce5_plot <- ggplot(amce5_df, aes(x = factor(attribute, level=c("Venezuela*Ambition", 
                                                                 "(Baseline = USA*No ambition)", 
                                                                 "Country*Politics:",
                                                                 "Political ambition",
                                                                 "(Baseline = No political ambition)",
                                                                 "Politics:",
                                                                 "Venezuela",
                                                                 "(Baseline = United States)",
                                                                 "Country:")), 
                                   y = effect, color = Subgroup)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.3, 0.5),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("figa7.eps", plot=amce5_plot, width=6.5, height=3.5, units="in")

# Results look very similar, but are ideology and democratic attitudes orthogonal?
cor(as.numeric(by_right$right), as.numeric(by_right$democracy), use="pairwise.complete.obs")
# With a correlation of about 0.001 it would be fair to say they are orthogonal in these data.
table(ind_level$right, ind_level$democracy)
summary(table(ind_level$right, ind_level$democracy))
```

Robustness extensions. Is the effect of savings & employment conditional on country? (Figures A8 and A9 in the appendix)
```{r savings_country}
# Using cjoint
amce4 <- cjoint::amce(selected ~ Empleo.previsto + País.de.retorno*Ahorros + Política,
              data = by_dem, cluster = TRUE, respondent.id = "respondentIndex")

amce41 <- cjoint::amce(selected ~ Empleo.previsto*País.de.retorno + Ahorros + Política,
               data = by_dem, cluster = TRUE, respondent.id = "respondentIndex")

summary(amce4)

amce4_df <- tibble(
  attribute = c("Savings:", "(Baseline = No savings)", "Savings from abroad", 
                "Intended employment:", "(Baseline = Self-employed)", "Looking for work",
                "Country:", "(Baseline = United States)", "Venezuela",
                "Politics:", "(Baseline = No political ambition)", "Political ambition",
                "Savings * Country", "(Baseline = No savings * USA)", "Savings * Venzuela"),
  effect = c(NA, 0, 0.17910, NA, 0, -0.12203, NA, 0, -0.19359, NA, 0, -0.12063, NA, 0, 0.0052234),
  lower_ci = c(NA, NA, 0.1606305, NA, NA, -0.1388635, NA, NA, -0.2121681, NA, NA, -0.1382183, NA, NA, -0.02429812),
  upper_ci = c(NA, NA, 0.1975695, NA, NA, -0.1051965, NA, NA, -0.1750119, NA, NA, -0.1030417, NA, NA, 0.03474492)
)

amce4_plot <- ggplot(amce4_df, aes(x = factor(attribute, level=c("Savings * Venzuela",
                                                                 "(Baseline = No savings * USA)",
                                                                 "Savings * Country",
                                                                 "Political ambition",
                                                                 "(Baseline = No political ambition)",
                                                                 "Politics:",
                                                                 "Venezuela",
                                                                 "(Baseline = United States)",
                                                                 "Country:",
                                                                 "Looking for work", 
                                                                 "(Baseline = Self-employed)", 
                                                                 "Intended employment:",
                                                                 "Savings from abroad",
                                                                 "(Baseline = No savings)",
                                                                 "Savings:")), 
                                   y = effect)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.4, 0.75),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("figa8.eps", plot=amce4_plot, width=6.5, height=3.5, units="in")

summary(amce41)

amce41_df <- tibble(
  attribute = c("Savings:", "(Baseline = No savings)", "Savings from abroad", 
                "Intended employment:", "(Baseline = Self-employed)", "Looking for work",
                "Country:", "(Baseline = United States)", "Venezuela",
                "Politics:", "(Baseline = No political ambition)", "Political ambition",
                "Employment * Country", "(Baseline = Self-employed * USA)", "Looking * Venzuela"),
  effect = c(NA, 0, 0.17908, NA, 0, -0.12215, NA, 0, -0.19369, NA, 0, -0.12055, NA, 0, 0.026826),
  lower_ci = c(NA, NA, 0.160609, NA, NA, -0.1389774, NA, NA, -0.2122624, NA, NA, -0.1381351, NA, NA, -0.00254656),
  upper_ci = c(NA, NA, 0.197551, NA, NA, -0.1053226, NA, NA, -0.1751176 , NA, NA, -0.1029649, NA, NA, 0.05619856)
)

amce41_plot <- ggplot(amce41_df, aes(x = factor(attribute, level=c("Looking * Venzuela",
                                                                   "(Baseline = Self-employed * USA)",
                                                                   "Employment * Country",
                                                                   "Political ambition",
                                                                   "(Baseline = No political ambition)",
                                                                   "Politics:",
                                                                   "Venezuela",
                                                                   "(Baseline = United States)",
                                                                   "Country:",
                                                                   "Looking for work", 
                                                                   "(Baseline = Self-employed)", 
                                                                   "Intended employment:",
                                                                   "Savings from abroad",
                                                                   "(Baseline = No savings)",
                                                                   "Savings:")), 
                                     y = effect)) +
  geom_point(position = position_dodge(0.3), size = 4) + 
  geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.4, linewidth = 1, 
                position = position_dodge(0.3)) +
  geom_hline(color = "black", yintercept = 0, linetype=3, linewidth=0.5) + 
  labs(title = "",
       x = "",
       y = "Change in Pr(Preferred Returnee)") +
  coord_flip() +
  theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold"),
                                            ),
                        legend.position = c(0.4, 0.75),
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")) +
  theme(axis.text.x = element_text(angle = 0, hjust = 1, face = "plain"))
ggsave("figa9.eps", plot=amce41_plot, width=6.5, height=3.5, units="in")
```

Robustness extensions. Using alternative control groups for democracy: the first group provides the strongest evidence, the second group (pro-democracy group the same, but we keep the control group limited) less so. 
```{r cond_dem}
# Using cjoint
amcealt1 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno*Política*demalt1,
                 data = by_alt1, cluster = TRUE, respondent.id = "respondentIndex",
                 respondent.varying = "demalt1")
summary(amcealt1)

amcealt2 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno*Política*demalt2,
                 data = by_alt2, cluster = TRUE, respondent.id = "respondentIndex",
                 respondent.varying = "demalt2")
summary(amcealt2) 
```

Robustness extensions. Rank:
```{r rank}
# Using cjoint
## Unconditional
rank1 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno + Política,
              data = conjoint_clean_rank, cluster = TRUE, respondent.id = "respondentIndex")

levels_uncon <- list()
levels_uncon[["Ahorros"]]<-c("No savings", "Savings from abroad")
levels_uncon[["Empleo.previsto"]]<-c("Self employed", "Looking for work")
levels_uncon[["País.de.retorno"]]<-c("United States", "Venezuela")
levels_uncon[["Política"]]<-c("No political ambition", "Political ambition")

plot(rank1, xlab = "Change in Rank Score", colors = "black", point.size = 0.7,
     plot.theme = theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold"),
                                            ),
                        legend.position = 'none',
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")),
     attribute.names = c("Savings", "Intended employment", "Country", "Politics"),
     level.names = levels_uncon)

## Conditional on employment
rank2 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto*work + País.de.retorno + Política,
              data = by_work_rank, cluster = TRUE, respondent.id = "respondentIndex",
              respondent.varying = "work")

plot(rank2, xlab = "Change in Rank Score", colors = "black", point.size = 0.7,
     plot.theme = theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold"),
                                            ),
                        legend.position = 'none',
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")),
     attribute.names = c("Savings", "Intended employment", "Country", "Politics"),
     level.names = levels_uncon, plot.display = "interaction")

## Conditional on democratic attitudes
rank3 <- cjoint::amce(selected ~ Ahorros + Empleo.previsto + País.de.retorno*Política*democracy,
              data = by_dem_rank, cluster = TRUE, respondent.id = "respondentIndex",
              respondent.varying = "democracy")

levels_uncon[["Paísderetorno:Política"]]<-c("USA*No ambition", "Venezuela*Ambition")

plot(rank3, xlab = "Change in Rank Score", colors = "black", point.size = 0.7,
     plot.theme = theme(axis.ticks = element_blank(),
                        axis.text.y = element_text(hjust = (0)),
                        text = element_text(size = 16,
                                            face = c("plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold",
                                                     "plain", "italic", "bold"),
                                            ),
                        legend.position = 'none',
                        panel.grid.major = element_line(colour = "grey90"),
                        panel.background = element_blank(),
                        axis.line = element_line(colour = "black")),
     attribute.names = c("Savings", "Employment", "Country", "Politics", "Country*Politics"),
     level.names = levels_uncon, plot.display = "interaction")
```

Robustness to incorporating interactions between each conjoint treatment and all other treatments (De la Cuesta, Egami and Imai, 2022). 
None of these interactions are significant, although we know from some of the earlier treatment heterogeneity analyses that there are interesting things going on in the subsets.
```{r dlcegimrobustness}
intr1 <- cjoint::amce(selected ~ Ahorros*Empleo.previsto + Ahorros*País.de.retorno + Ahorros*Política,
              data = conjoint_clean, cluster = TRUE, respondent.id = "respondentIndex") 
summary(intr1)
intr2 <- cjoint::amce(selected ~ Ahorros*Empleo.previsto + Empleo.previsto*País.de.retorno +
                        Empleo.previsto*Política,
              data = conjoint_clean, cluster = TRUE, respondent.id = "respondentIndex") 
summary(intr2)
intr3 <- cjoint::amce(selected ~ País.de.retorno*Empleo.previsto + Ahorros*País.de.retorno +
                        País.de.retorno*Política,
              data = conjoint_clean, cluster = TRUE, respondent.id = "respondentIndex") 
summary(intr3)
intr4 <- cjoint::amce(selected ~ Política*Empleo.previsto + Política*País.de.retorno + Ahorros*Política,
              data = conjoint_clean, cluster = TRUE, respondent.id = "respondentIndex") 
summary(intr4)
```

Given the experimental design, all variables should have a .5 probability of having either value, both in the aggregate and the subset analyses. Is that indeed the case? Note that variables are measured 1 and 2, not 0 and 1, so we need to subtract 1 from all means to arrive at the proportions. 
```{r random_check}
# Pooled analysis
propcheck1 <- conjoint_clean %>% 
  mutate(x = 1) %>% 
  group_by(x) %>% 
  summarise(prop_savings = mean(as.numeric(Ahorros)),
            prop_employ = mean(as.numeric(Empleo.previsto)),
            prop_country = mean(as.numeric(País.de.retorno)),
            prop_politic = mean(as.numeric(Política)))
summary(propcheck1)
# Subset analysis, Work
propcheck21 <- by_work_alt %>% 
  filter(work_alt == 1) %>% 
  group_by(work_alt) %>%
  summarise(prop_savings = mean(as.numeric(Ahorros)),
            prop_employ = mean(as.numeric(Empleo.previsto)),
            prop_country = mean(as.numeric(País.de.retorno)),
            prop_politic = mean(as.numeric(Política)))
summary(propcheck21)
propcheck22 <- by_work_alt %>% 
  filter(work_alt == 0) %>% 
  group_by(work_alt) %>%
  summarise(prop_savings = mean(as.numeric(Ahorros)),
            prop_employ = mean(as.numeric(Empleo.previsto)),
            prop_country = mean(as.numeric(País.de.retorno)),
            prop_politic = mean(as.numeric(Política)))
summary(propcheck22)
# Subset analysis, democracy
propcheck31 <- by_dem %>% 
  filter(democracy == 1) %>% 
  group_by(democracy) %>% 
  summarise(prop_savings = mean(as.numeric(Ahorros)),
            prop_employ = mean(as.numeric(Empleo.previsto)),
            prop_country = mean(as.numeric(País.de.retorno)),
            prop_politic = mean(as.numeric(Política)))
summary(propcheck31)
propcheck32 <- by_dem %>% 
  filter(democracy == 0) %>% 
  group_by(democracy) %>% 
  summarise(prop_savings = mean(as.numeric(Ahorros)),
            prop_employ = mean(as.numeric(Empleo.previsto)),
            prop_country = mean(as.numeric(País.de.retorno)),
            prop_politic = mean(as.numeric(Política)))
summary(propcheck32)
```
